<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function f(val) {
            var a = document.getElementById(val);
            if (a.value.length>0){
                document.getElementById('ts').innerText="";
            } else {
                document.getElementById('ts').innerText="请输入密码";
            }
        }
    </script>
</head>
<body>
    用户名:<input type="text"><br>
    密&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="password" id="a" onkeyup="f(this.id)"><font id="ts">请输入密码</font>
</body>
</html>